﻿using System; 
using System.Collections.Generic; 
using System.ComponentModel; 

namespace DataAccess{
[Serializable]
[GenWiseAttribute(IsDataSourceEntity = true) ]
public class answer : INotifyPropertyChanged
 {


#region --- Class Fields / Objects  ---

[NonSerialized]
protected PropertyChangedEventHandler _propertyChanged;
private System.Int32 _question_id;
private System.Int32 _user_id;
private System.String _answer_text;
private question _question;
private user _user;

#endregion


#region --- Class Properties ---

public virtual System.Int32 question_id 
{
get
{
return _question_id;
}
set 
{
if ( _question_id != value) 
{
_question_id = value ;
OnPropertyChanged("question_id");
}
}
}

public virtual System.Int32 user_id 
{
get
{
return _user_id;
}
set 
{
if ( _user_id != value) 
{
_user_id = value ;
OnPropertyChanged("user_id");
}
}
}

public virtual System.String answer_text 
{
get
{
return _answer_text;
}
set 
{
if ( _answer_text != value) 
{
_answer_text = value ;
OnPropertyChanged("answer_text");
}
}
}

/// <summary>
/// Generated from Relation FK_Answer_Question
/// </summary>
[GenWiseAttribute(RelationID = "40ff00f1-a175-49b9-bcea-2191231f135d") ]
public virtual question question 
{
get
{
if ( _question == null ) 
{
if (  _question_id.Equals(0)  || _question_id.Equals(System.Int32.MinValue) ) 
{
if ( _question != null && ( _question.id.Equals(System.Int32.MinValue) ) )
{
  _question = null;
}
}
else
{
_question = (new questionFactory()).Get(_question_id);
}
}

return _question;
}
set 
{
if ( _question != value) 
{
if ( value==null ) _question_id = System.Int32.MinValue; else _question_id = (System.Int32)value.id; 
_question = value ;
}
}
}

/// <summary>
/// Generated from Relation FK_Answer_User
/// </summary>
[GenWiseAttribute(RelationID = "952cc762-c03f-401d-a4e1-1820d9ab0ce6") ]
public virtual user user 
{
get
{
if ( _user == null ) 
{
if (  _user_id.Equals(0)  || _user_id.Equals(System.Int32.MinValue) ) 
{
if ( _user != null && ( _user.id.Equals(System.Int32.MinValue) ) )
{
  _user = null;
}
}
else
{
_user = (new userFactory()).Get(_user_id);
}
}

return _user;
}
set 
{
if ( _user != value) 
{
if ( value==null ) _user_id = System.Int32.MinValue; else _user_id = (System.Int32)value.id; 
_user = value ;
}
}
}

/// <summary>
/// Property that simulates a unique PK by concatenating all the Pk properties
/// </summary>
public virtual System.String VirtualPk 
{
get
{
string _retValue = string.Empty;

_retValue += question_id.ToString();

_retValue += "^";
_retValue += user_id.ToString();

return _retValue;

}
}

/// <summary>
/// Is this object Valid? 
/// </summary>
/// <remarks>
/// This is achieved by counting how many errors are returned from the Validate() method. If no errors are found then it's valid.
/// </remarks>
[Bindable(false)]
public virtual System.Boolean IsValid 
{
get
{
List<Error> _errors = this.Validate(); if ( _errors.Count > 0 ) return false; else return true;
}
}


#endregion


#region --- Class Methods --- 

/// <summary>
/// Raises PropertyChanged event.
/// </summary>
protected virtual void OnPropertyChanged(System.String ppropertyChanged)
{
if (_propertyChanged != null) _propertyChanged( this , new PropertyChangedEventArgs(ppropertyChanged));

}

/// <summary>
/// Create a new answer object. 
/// </summary>
public  answer()
{
}

/// <summary>
/// Create a new instance/object
/// </summary>
public  answer(System.Int32 pquestion_id , System.Int32 puser_id)
{
_question_id = pquestion_id ;
_user_id = puser_id ;

}

public override int GetHashCode()
{
string _hash = String.Empty; 
_hash += question_id.ToString();
_hash += user_id.ToString();
return _hash.GetHashCode(); 

}

public override bool Equals(object pobject)
{
answer _newanswer = (pobject as answer); 
if (_newanswer == null ) return false; 
if (_newanswer.GetHashCode() == this.GetHashCode() ) return true; 
return false; 

}

/// <summary>
/// Validates the object returning a list of errors if the validation fails.
/// </summary>
/// <remarks>
/// You can use the provided User CodeBlocks to add your own validations.
/// </remarks>
///<returns>Returns the List of Errors found during the Validation. If no errors are found null is returned.<returns>
public virtual List<Error> Validate()
{
List<Error> _errors = new List<Error>();

// Primary Key Validation (Template Option)
if (  question_id.Equals(0)  ) 
{
   _errors.Add( new Error( "The PK Column (question_id) can not be null!. " ) );
}
if (  user_id.Equals(0)  ) 
{
   _errors.Add( new Error( "The PK Column (user_id) can not be null!. " ) );
}

return _errors;
}


#endregion


#region --- Class Events  ---

public event PropertyChangedEventHandler PropertyChanged 
{
   add {
_propertyChanged+= value;
   }
   remove {
_propertyChanged-= value;
   }
}


#endregion
}
}

